<template>
  <div>
    <el-dialog title="编辑直播列表" :visible="editDialogVisible" @close="close">
      <el-form ref="formRef" :rules="rules" label-width="120px">
        <el-form-item prop="name" label="员工名字:">
          <el-input v-model="formData.name" placeholder=""></el-input>
        </el-form-item>
        <el-form-item prop="age" label="员工年龄:">
          <el-input v-model="formData.age" placeholder=""></el-input>
        </el-form-item>
        <el-form-item prop="phone" label="员工手机号:">
          <el-input v-model="formData.phone" placeholder=""></el-input>
        </el-form-item>
        <el-form-item prop="idNumber" label="员工身份证:">
          <el-input v-model="formData.idNumber" placeholder=""></el-input>
        </el-form-item>
        <el-form-item prop="sex" label="员工性别:">
          <el-input v-model="formData.sex" placeholder=""></el-input>
        </el-form-item>
        <!-- 按钮 -->
        <el-form-item>
          <el-row type="flex" justify="center">
            <el-col :span="12">
              <el-button size="mini" type="primary" @click="btnOk"
                >确认</el-button
              >
              <el-button size="mini" type="primary" @click="close"
                >取消</el-button
              >
            </el-col>
          </el-row>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { employeeUpdateApi } from "@/api/employee";
export default {
  props: {
    editDialogVisible: {
      type: Boolean,
      default: false,
    },
    id: {
      type: Number,
      default: false,
    },
  },
  data() {
    return {
      formData: {
        name: '',
        age: "",
        phone: "",
        idNumber: "",
        sex: "",
      },
      rules: {
        name: [{ required: true, message: "请输入名字", trigger: "blur" }],
        age: [{ required: true, message: "请输入年龄", trigger: "blur" }],
        phone: [
          { required: true, message: "请输入手机号", trigger: "blur" },
          {
            pattern: /^1[3-9]\d{9}$/,
            message: "请填写正确的手机号",
          },
        ],
        idNumber: [
          { required: true, message: "请输入用户id", trigger: "blur" },
        ],
        sex: [{ required: true, message: "请输入性别", trigger: "blur" }],
      },
    };
  },
  methods: {
    // 关闭弹层
    close() {
      // 重置表单数据
      this.$refs.formRef.resetFields();
      // 清空表单数据
      this.formData = {};
      // 通知父组件关闭弹层
      this.$emit("update:editDialogVisible", false);
    },
    // 点击确认
    async btnOk(rows) {
      console.log(rows);
      // 表单校验
      await this.$refs.formRef.validate();
      const res = employeeUpdateApi(this.formData, this.id);
      console.log(res);
      // // 通知父组件更新数据
      this.$message.success("修改成功");
      this.close();
      // this.$emit('employeeList')
      this.$parent.employeeList();
    },
  },
};
</script>

<style scoped></style>
